//
//  NSString+FontSize.m
//  WBusiness
//
//  Created by HuangZhen on 2016/10/9.
//  Copyright © 2016年 HuangZhen. All rights reserved.
//

#import "NSString+FontSize.h"

@implementation NSString (FontSize)

- (CGSize)suggestedSizeWithFont:(UIFont *)font width:(CGFloat)width {
    
    if (NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_7_0) {
        CGRect bounds = [self boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: font} context:nil];
        return bounds.size;
    }else{
        //弃用的
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        return [self sizeWithFont:font
                constrainedToSize:CGSizeMake(width, CGFLOAT_MAX)
                    lineBreakMode:NSLineBreakByWordWrapping];
#pragma clang diagnostic pop
    }

}
@end
